<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <meta http-equiv="X-UA-Compatible" content="ie=edge">
    <title>ES6-Demo演示</title>
</head>
<body>
    <h2>
        ES6-Demo演示
    </h2>
<script>
    // rest参数
    function sum(...m) { //在这地方...m就是rest参数，，不定参数
            let total = 0;
            for (var i of m) {
                total += i;
            }
            console.log(`total:${total}`)
        }
        sum(1, 2, 2, 3);
    // ES6的箭头函数
        let sum2 = (...m) => {
            let total = 0;
            for (var i of m) {
                total += i;
            }
            console.log(`total:${total}`)
        };
        sum2(1,2);
    //数组的扩展
    var [x,y] = [4,8]; //结构
    console.log(...[4,8]);// ...于数组结合就是数组的扩展，它是运算符，作用是把数组中的元素进行扩展，并输出

    //例子——把两个数组进行合并
    let arr1 = [1,2,3];
    let arr2 = [4,5,6];
    console.log("传统合并concat" + arr1.concat(arr2));

    console.log("ES6的合并" + [...arr1,...arr2]);

    var [x,...y] = [1,2,3,4,5];    //加入...后y变成了数组

    let xy = [...'ES6'];//
    //函数的扩展

</script>
</body>
</html>